<template>
	<view>
		<z-nav-bar title="发起答疑"></z-nav-bar>
		<view class="content">
			<view class="left">
				<view class="row">擅长领域</view>
				<view class="row" :class="fieldID===0?'active':''" @click="fieldSwitch(0)">全部</view>
				<view class="row" :class="fieldID===item.dictCode?'active':''" v-for="item in fieldData"
					:key="item.dictCode" @click="fieldSwitch(item.dictCode)">{{item.dictLabel}}</view>
			</view>
			<view class="line"></view>
			<view class="right">
				<view class="one">第一步：选择高手</view>
				<view v-if="coachData && coachData.length">
					<view v-for="item in coachData" :key="item.instructorId">
						<view class="row" @click="toIm(item.instructorId)">
							<view class="user">
								<image class="flex_sh" :src="setting.oss_pub_domain+item.instructorAvatar"></image>
								<view>
									<view class="img flex_sh">{{item.instructorName}}<text>{{item.introduce}}</text></view>
									<view class="tag">擅长: <text v-for="(words,index) in item.expertiseArea"
											:key="index">{{words}}</text></view>
								</view>
							</view>
							<view class="auth">
								<view>已认证</view>
								<text class="score">消耗积分: {{item.consumeIntegral}}个</text>
							</view>
							<image class="more" :src="`${setting.sImgUrl}/index/fanhui_next@2x.png`"></image>
						</view>
						<view class="lines"></view>
					</view>
				</view>
				<view v-else class="text-c uni-mt-32 uni-585C66">暂无教练</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		qaInstructor,
		learn_focus,
		createlmGroup
	} from '@/api/student';
	export default {
		data() {
			return {
				nav: '',
				fieldData: [],
				fieldID: 0,
				coachData: []
			}
		},
		methods: {
			async fieldSwitch(id) {
				//获取教练列表
				this.fieldID = id
				const res = await qaInstructor({
					expertiseArea: id === 0 ? '' : id
				})
				// console.log(res)
				res.rows.forEach((el) => {
					el.expertiseArea = el.expertiseArea.split(',')
				})
				this.coachData = res.rows
			},
			async toIm(id) {
				const result = await createlmGroup(id)
				uni.navigateTo({
					url: '/uni_modules/uni-im/pages/chat/chat?conversation_id=group_' + result,
					animationDuration: 300
				})
			},
		},
		onLoad() {
			//获取领域列表
			learn_focus().then(res => {
				// console.log(res)
				this.fieldData = res
			})
			this.fieldSwitch(0)
		},
		onShow() {
			// #ifdef MP-WEIXIN
			this.nav = uni.getMenuButtonBoundingClientRect().height
			// #endif
		}
	}
</script>

<style scoped>
	@import url('./answer.css');
</style>